package com.smartinput.voice.controller

import com.mensanyun.kotool.util.executeQueryWithTry
import com.smartinput.voice.application.service.SpeechRecognitionManager
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/api/speech")
class SpeechRecognitionStatusController(
    private val speechRecognitionManager: SpeechRecognitionManager
) {

    @GetMapping("/status")
    fun getSpeechRecognitionStatus() = executeQueryWithTry {
        val serviceInfo = speechRecognitionManager.getCurrentServiceInfo()
        
        mapOf(
            "currentService" to serviceInfo.serviceName,
            "availableServices" to serviceInfo.availableServices,
            "isAvailable" to serviceInfo.isAvailable,
            "timestamp" to System.currentTimeMillis()
        )
    }

    @PostMapping("/test")
    fun testSpeechRecognition(@RequestBody audioData: ByteArray) = executeQueryWithTry {
        val result = speechRecognitionManager.recognizeAudio(audioData)
        
        mapOf(
            "success" to result.success,
            "text" to result.text,
            "confidence" to result.confidence,
            "error" to result.error,
            "service" to speechRecognitionManager.getCurrentServiceInfo().serviceName
        )
    }
} 